import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//import './api/mock'
import Cookie from 'js-cookie'
Vue.config.productionTip = false
Vue.use(ElementUI);

import axios from 'axios'
import VueAxios from 'vue-axios'
axios.defaults.withCredentials = true
Vue.use(VueAxios, axios);

axios.defaults.baseURL = 'http://101.43.44.19:8100'

axios.interceptors.request.use(config => {
  config.headers.token = Cookie.get("token")
  return config
})

router.beforeEach((to, from, next) => {
  let geturl = window.location.href
  let getqyinfo = geturl.split('?')[1]
  let getqys = new URLSearchParams('?'+getqyinfo)
  let getqycode = getqys.get('DSESSION')
  if( getqycode ){
    Cookie.set("DSESSION",getqycode)
  }
  if(Cookie.get("DSESSION") == 'null' && to.path != '/home'){
    next('/home');
  }
  // const token = Cookie.get('token')
  next();
  // if (!token && to.path === '/register' || !token && to.path === '/identification' || !token && to.path === '/Login' || !token && to.path === '/forgetPassword') {
  //   next();
  // } else {
  //   if (!token && (to.path !== '/')) {
  //     next('');
  //   } else {
  //     next();
  //   }
  // }

})

new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    store.commit('addMenu', router)
  }
}).$mount('#app')
